import "./index.css";
import { Button, message } from "antd";

function Card({ course }) {
  const jumpCourse = (url) => {
    if (url) {
      window.open(url, "_blank");
    } else {
      message.info(
        "请等待更新购买链接，感谢支持。也可以在上边的优惠规则中添加微信询问链接"
      );
    }
  };
  return (
    <div
      className="Card"
    >
      <div>
        <img alt="img" referrerPolicy="no-referrer" className="coverImage" src={course.coverImg} />
      </div>
      <div className="content">
        <div className="info">
          <div className="title">{course.title}</div>
          <div className="author">{course.summary}</div>
          <div className="people">{course.buyCount} 人已学习</div>
        </div>
        <div className="action">
          <div className="action-left">
            {course.isDiscount && (
              <div className="price">
                <div className="promotion">限时 : ¥{course.discountPrice}</div>
                <div className="origin">原价 : ¥{course.price}</div>
              </div>
            )}
            {!course.isDiscount && (
              <div className="price">
                <div className="promotion">¥{course.price}</div>
              </div>
            )}
            <div className="return">
              成功购买后可得红包¥{course.returnRedPacket}
            </div>
          </div>
          <div className="aciton-right"
            
          >
            {course.shareUrl ? (
              <Button className="button" shape="round" type="primary" onClick={() => {
                jumpCourse(course.shareUrl);
              }}>
                立即购买
              </Button>
            ) : (
              <Button className="button" shape="round" type="primary">
                等待更新
              </Button>
            )}
          </div>
        </div>
      </div>
    </div>
  );
}

export default Card;